<%@ page language="java" contentType="text/html; charset=utf-8" import="java.util.*,java.text.SimpleDateFormat,com.javabean.*,com.model.*"
    pageEncoding="UTF-8" %>
<%@ page import="java.net.URLEncoder"%>
<%@ page import="java.net.URLDecoder"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>会议室预约</title>
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	background-color: #fff;
}
.tabfont01 {	
	font-family: "宋体";
	font-size: 9px;
	color: #555555;
	text-decoration: none;
	text-align: center;
}
.font051 {font-family: "宋体";
	font-size: 12px;
	color: #333333;
	text-decoration: none;
	line-height: 20px;
}
.font201 {font-family: "宋体";
	font-size: 12px;
	color: #FF0000;
	text-decoration: none;
}
.button {
	font-family: "宋体";
	font-size: 14px;
	height: 37px;
}
html { overflow-x: auto; overflow-y: auto; border:0;} 
-->
</style>

<link href="../css/css.css" rel="stylesheet" type="text/css" />
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<script src="../js/jquery-1.9.0.js"></script>
</head>
<script language=JavaScript>
function sbbj(){
	opener.document.getElementById("mainFrame")
}
function sousuo(){
	window.open("gaojisousuo.htm","","depended=0,alwaysRaised=1,width=800,height=510,location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0");
}
function selectAll(){
	var obj = document.fom.elements;
	for (var i=0;i<obj.length;i++){
		if (obj[i].name == "delid"){
			obj[i].checked = true;
		}
	}
}

function unselectAll(){
	var obj = document.fom.elements;
	for (var i=0;i<obj.length;i++){
		if (obj[i].name == "delid"){
			if (obj[i].checked==true) obj[i].checked = false;
			else obj[i].checked = true;
		}
	}
}
function link() {
	var obj = document.fom.elements;
	var x = 0;
	for (var i=0;i<obj.length;i++){
		if (obj[i].checked == true){
			x++;
		}
	}
	if(x>0){
		if(confirm("确认同意所选预约?")){
			document.getElementById("fom").action = "MeetingRoomDeal?flag=agreeReserve";
			document.getElementById("fom").submit();
		}
	}
	else{
		alert("请选择需要同意的预约");
		return;
	}
}
function link1() {
	var obj = document.fom.elements;
	var x = 0;
	for (var i=0;i<obj.length;i++){
		if (obj[i].checked == true){
			x++;
		}
	}
	if(x>0){
		if(confirm("确认拒绝所选预约？")){
			document.getElementById("fom").action = "MeetingRoomDeal?flag=disagreeReserve";
			document.getElementById("fom").submit();
		}
	}
	else{
		alert(请选择需要拒绝的预约);
		return;
	}
}
function link2() {
	document.getElementById("fom").action = "MeetingRoomDeal?flag=deleteReserve";
	document.getElementById("fom").submit();
}
function link3() {
	document.getElementById("fom").method = "get";
	document.getElementById("fom").action = "meetingRoom.jsp";
	document.getElementById("fom").submit();
}
function link4() {
	if($("#textfield3").val()==""||null){
		alert("请输入页数！");
		return;
	}
	document.getElementById("fom").method = "post";
	document.getElementById("fom").action = "meetingRoom.jsp?flag=go";
	document.getElementById("fom").submit();
}


</script>

<body bgcolor="#fff">
<%
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");

MeetingService ms=new MeetingService();
ArrayList<MeetingRoom> rooms=new ArrayList<MeetingRoom>();
String choice=request.getParameter("choice");
String flag=request.getParameter("flag");
String input=(String)request.getParameter("input");
String spageCountNow=request.getParameter("pageCountNow");
int reserveID=0;
/*
try{
	byte a[] = choice.getBytes("iso-8859-1");
	choice = new String(a,"utf-8");
}catch(Exception e){}
*/
//System.out.println(choice);
if(choice==null||choice==""){
	 choice="\u65f6\u95f4";
		}
//System.out.println(choice);ReserveID

if(input==null){
	input="";
}
//System.out.println("choice="+choice+"input="+input);
int pageCountNow=1;
int pagePrev=1;
int pageNext=1;

;
//go

//
if("go".equals(flag)){
	spageCountNow=request.getParameter("goto");
	choice=(String)request.getParameter("gochoice");
	input=(String)request.getParameter("goinput");
}else if("agree".equals(flag)){
	reserveID=Integer.parseInt((String)request.getParameter("ReserveID"));
	ms.changeRoomState(3, reserveID);
}else if("disagree".equals(flag)){
	reserveID=Integer.parseInt((String)request.getParameter("ReserveID"));
	ms.changeRoomState(4, reserveID);
}
int countTotal=ms.totalNumber(choice,input);
int pageTotal=(countTotal%10==0)?countTotal/10:countTotal/10+1;
//System.out.println("pageTotal="+pageTotal);
//System.out.println("flag:"+flag);
//System.out.println("choice="+choice+"input="+input);
if(spageCountNow!=null){
	pageCountNow=Integer.parseInt(spageCountNow);
}
if(pageCountNow==1)
	pagePrev=pageTotal;
else pagePrev = pageCountNow-1;
if(pageCountNow==pageTotal)
	pageNext = 1;
else pageNext = pageCountNow+1;


if(choice.equals("时间")){
	rooms=ms.findRooms(input, pageCountNow);
	
}else if(choice.equals("会议室")){
	if(input.equals("B2-617")){
		rooms=ms.findRoomsByID(1, pageCountNow);
	}else if(input.equals("B2-708")){
		rooms=ms.findRoomsByID(2, pageCountNow);
	}else if(input.equals("B2-810")){
		rooms=ms.findRoomsByID(3, pageCountNow);
	}else if(input.equals("B2-811")){
		rooms=ms.findRoomsByID(4, pageCountNow);
	};
};
//从session中取出用户的级别
int userGrade = ((User) request.getSession(true).getAttribute(
		"user")).getUserGrade();
boolean isAuthority=false;
if(userGrade >= 8)
{
	isAuthority=true;
}
%>
<form name="fom" id="fom" method="post" >
<table width="100%" border="0" cellspacing="0" cellpadding="0">

  <tr>
    <td height="30">      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td height="62" background="../image/widgetbg5.jpg">
            
		   <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
		    <tr>
			  <td width="24"><img src="../images/ico07.gif" width="20" height="18" /></td>
			  <td width="519"><select name="choice">
				    <option value="时间">时间</option>
				    <option value="会议室">会议室</option>
			      </select>
			   <input name="input" type="text" size="12" />
			   <input name="sumb" type="button"  value="查 询" onclick="link3()""/></td>
			   <td width="679" align="left"><a href="#" onclick="sousuo()">
			   </a></td>	
		    </tr>
          </table></td>
        </tr>
    </table></td></tr>
  <tr>
    <td><table id="subtree1" style="DISPLAY: " width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td><table width="95%" border="0" align="center" cellpadding="5" cellspacing="0">
          	 <tr>
          	 <%if(isAuthority){ %>
               <td height="20"><span class="newfont07">选择：<a href="#" class="right-font08" onclick="selectAll();">全选</a>-
               <a href="#" class="right-font08" onclick="unselectAll();">反选</a></span>
		           <input name="Submit" type="button"  value="同意预约"  onclick="link()"/> 
                   <input name="Submit" type="button"  value="拒绝预约" onclick="link1()" />
	              </td>
	              <% }%>
          </tr>
              <tr>
                <td height="40" class="font42"><table width="100%" border="0" cellpadding="4" cellspacing="1" bgcolor="#464646" class="newfont03">
					<tr>
                    <td height="20" colspan="7" align="center" class="tablestyle_title">会议室预约信息列表</td>
                    </tr>
                  <tr>
				    <td width="5%" align="center" class="zsd">选择</td>
					<td width="15%" height="20" align="center" class="zsd">时间</td>
                    <td width="15%" align="center" class="zsd">会议室</td>
                    <td width="15%" align="center" class="zsd">借用部门</td>
                    <td width="15%" align="center" class="zsd">联系人</td>
                    <td width="20%" align="center" class="zsd">是否预约成功</td>
                    <td width="15%" align="center" class="zsd">操作</td>
                  </tr>
                  <%int len=rooms.size();
                  for(int i=0;i<len;i++){
                	  MeetingRoom room=rooms.get(i);
                	  String roomID="B2-617";
                	  String state="未批准";
                	  if(room.getRoomID()==2){
                		  roomID="B2-708";
                	  }else if(room.getRoomID()==3){
                		  roomID="B2-810";
                	  }else if(room.getRoomID()==4){
                		  roomID="B2-811";
                	  };
                	  if(room.getState()==2){
                		  state="未批准";
                	  }else if(room.getState()==3){
                		  state="已批准";
                	  }else if(room.getState()==4){
                		  state="拒绝通过";
                	  }
                	  int ReserveID=room.getReserveID();
                  %>
                  <tr align="center">
				    <td bgcolor="#FFFFFF"><input type="checkbox" name="delid" value="<%=(room.getReserveID())%>"/></td>
					<td height="20" bgcolor="#FFFFFF"><a href="#"></a><%=room.getReserveDate() %></td>
                    <td bgcolor="#FFFFFF"><%=roomID %></td>
                    <td bgcolor="#FFFFFF"><%=room.getDepartment() %></td>
                    <td bgcolor="#FFFFFF"><%=room.getConnectorName() %></td>
                    <td bgcolor="#FFFFFF"><%=state %></td>
                    <td bgcolor="#FFFFFF"><a href="meeting_CK.jsp?ReserveID=<%=ReserveID%>">查看</a>
                                          <a href="meetingRoom.jsp?pageCountNow=<%=pageCountNow %>&choice=<%=choice%>&input=<%=input%>&ReserveID=<%=ReserveID%>&flag=agree">同意</a>
                                          <a href="meetingRoom.jsp?pageCountNow=<%=pageCountNow %>&choice=<%=choice%>&input=<%=input%>&ReserveID=<%=ReserveID%>&flag=disagree">拒绝</a></td>
                  </tr>
                  <%} %>
                </table></td>
              </tr>
            </table></td>
        </tr>
      </table>
      <table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td height="33"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="right-font08">
              <tr>
                <td width="50%">共 <span class="right-text09"><%=pageTotal %></span> 页 | 第 <span class="right-text09"><%=pageCountNow %></span> 页</td>
                <td width="49%" align="right">[<a href="meetingRoom.jsp?pageCountNow=1&choice=<%=choice%>&input=<%=input%>" class="right-font08">首页</a> | <a href="meetingRoom.jsp?pageCountNow=<%=pagePrev %>&choice=<%=choice%>&input=<%=input%>" class="right-font08">上一页</a> | 
                <a href="meetingRoom.jsp?pageCountNow=<%=pageNext %>&choice=<%=choice%>&input=<%=input%>" class="right-font08">下一页</a> | <a href="meetingRoom.jsp?pageCountNow=<%=pageTotal %>&choice=<%=choice%>&input=<%=input%>" class="right-font08">末页</a>] 转至：</td>
                <td width="1%"><table width="20" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="1%"><input id="textfield3" name="goto" type="text" class="right-textfield03" size="1" /></td>
                      <td width="87%"><input name="Submit23222" type="button" class="right-button06" value=" " onclick="link4()"/> </td>
                      <td width="1%"><input name="gochoice" type=hidden size="1" value="<%=choice%>" /></td>
                      <td width="1%"><input name="goinput" type="hidden" size="1" value="<%=input%>"/></td>
                    </tr>
                </table></td>
              </tr>
          </table></td>
        </tr>
      </table></td>
  </tr>
</table>
</form>
</body>
</html>